/**
 * +======================================================================================================================+
 * @Author: CimZzz
 * @Date: 2022-09-08 11:52:38
 * 
 * 代码分割块，以下内容涉及: 
 * 
 * 针对消息队列线程的测试用例
 * 
 */
#include <cstdio>
#include "vl_message_queue.h"

using namespace VL;

int main(int argc, char ** argv) {
	VLMessageQueueThread msgThread([&](const std::shared_ptr<VLMessageQueueData>& dataPtr) {
		printf("recv data: %d\n", *dataPtr->memoryCast<int>());
		std::this_thread::sleep_for(std::chrono::seconds(2));
	});
	bool isRunning = true;
	while(isRunning) {
		char c = getchar();
		switch(c) {
			case 's':
				msgThread.loop();
				msgThread.enqueue(1);
				break;
			case 'a':
				msgThread.enqueue(1);
				break;
			case 'b':
				msgThread.enqueueFirst(2);
				break;
			case 'c':
				msgThread.clear();
				break;
			case 'd':
				msgThread.destroyUntil();
				break;
			case 'e':
				msgThread.destroy();
				break;
			case 'f':
				msgThread.waitDestroy();
				break;
			case 'q':
				// 停止循环
				isRunning = false;
				break;
		}
	}

	return 0;
}